package config

import (
	"fmt"
	"gopkg.in/yaml.v3"
	"log"
	"os"
)

// Conf 配置文件
type Conf struct {
	Database Database `yaml:"database"`
	Es       Es       `yaml:"es"`
}

type Database struct {
	Mysql        string `yaml:"mysql"`
	MaxIdleConns int    `yaml:"max_idle_conns"`
	MaxOpenConns int    `yaml:"max_open_conns"`
}

type Es struct {
	Host []string `yaml:"host"`
	User string   `yaml:"user"`
	Pwd  string   `yaml:"pwd"`
}

var Confok Conf

// InitConf 获取配置文件方法
func InitConf() {
	yamlFile, err := os.ReadFile("./conf/config.yaml")
	if err != nil {
		fmt.Println(err.Error())
	}
	err = yaml.Unmarshal(yamlFile, &Confok)
	if err != nil {
		fmt.Println(err.Error())
	}
	log.Println("配置文件初始化...")
}
